package study.test.ld;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import lombok.extern.log4j.Log4j;

/**
 * 异步对http 进行刷新
 * 
 * @ClassName HttpPostThread
 * @author <a href="892042158@qq.com" target="_blank">于国帅</a>
 * @date 2018年5月9日 下午4:33:37
 *
 */
@Log4j
public class HttpPostThread implements Runnable {
    public static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(6, 20, 20000, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(100000));

    private String callbackurl;

    public HttpPostThread(String callbackurl) {
        this.callbackurl = callbackurl;
    }

    public static void toInitialize() {
        EXECUTOR.allowCoreThreadTimeOut(true); // 该值为true,核心线程存活时间生效
        // 这里对未完整刷新完成的进行 回补
    }

    @Override
    public void run() {
        try {
//            HttpUtil.postData(callbackurl, null);
            System.err.println("HttpPostThread:" + Thread.currentThread().getName() + "callbackurl:" + callbackurl);
        } catch (Exception e) {
            log.error("HttpPostThread 出现异常", e);
        }
    }

    public static void shutdown() {
        EXECUTOR.shutdown();
    }

}
